﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Demo02
{
    public partial class FrmScanData : Form
    {
        private string _sScanResultFile = @"\Application Data\ScanData.txt";
        public FrmScanData()
        {
            InitializeComponent();
            LoadData();
        }

        private void LoadData()
        {
            if (!File.Exists(_sScanResultFile))
            {
                MessageBox.Show("数据文件不存在！");
                return;
            }
            using (StreamReader sr = new StreamReader(_sScanResultFile, System.Text.Encoding.Default))
            {
                String sLine;
                while ((sLine = sr.ReadLine()) != null)
                {
                    List<string> sList = MotoCommon.MotoCommon.splitStr(sLine, ',');
                    if (sList.Count == 4)
                    {
                        try
                        {
                            MyGoods record = new MyGoods();
                            record.BarCode = sList[0];
                            record.GoodsName = sList[1];
                            record.GoodsAmount = int.Parse(sList[2]);
                            record.GoodsDate = sList[3];

                            listBox1.Items.Add(string.Format("{0}{1}{2}{3}",
                                 MotoCommon.MotoCommon.str2print(record.BarCode, 1),
                                   MotoCommon.MotoCommon.str2print(record.GoodsName, 1),
                                   MotoCommon.MotoCommon.str2print(record.GoodsAmount.ToString(), 2),
                                   MotoCommon.MotoCommon.str2print(record.GoodsDate, 3)));
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }


            }
            //foreach (MyGoods record in FrmMain.ScanGoodsList)
            //{

            //}
        }

        private void FrmScanData_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)120)
            {
                this.Close();
                return;
            }
            else if (e.KeyValue == (char)121)	// 按"F"+"F2"键
            {
                //显示数据列表
                MotoCommon.MotoReaderAction.turnOnBacklight();
            }
            else if (e.KeyValue == (char)114)	// 按"F"+"F2"键
            {
                //显示数据列表
                MotoCommon.MotoReaderAction.turnOffBacklight();
            }
        }
    }
}